import request from '@/utils/request';

export const getCommentsByIdAPI = (id: string, type: 'a' | 'c', last_id?: string) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type,
      source: id,
      offset: last_id,
    },
  });
};

export interface SendCommentParms {
  /** 文章id或者评论lid */
  target: string;
  /** 评论内容 */
  content: string;
  /** 对评论回复时，需要传的文章id */
  art_id?: string;
}

export const sendCommentByIdAPI = (data: SendCommentParms) => {
  return request({
    url: '/v1_0/comments',
    method: 'post',
    data,
  });
};

export const likeCommentByIdAPI = (target: string) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target,
    },
  });
};

export const dislikeCommentByIdAPI = (target: string) => {
  return request({
    url: '/v1_0/comment/likings/' + target,
    method: 'delete',
  });
};
